﻿//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
/* and trade secrets of Foxit Software Inc.      
**************************************************************************
*/

/**
* Thmubnail插件类；
* 需求的plugin: navigation panel;
*/



define(function (require, exports, module) {
    var CPDF_PageThumbsView = require("./PDFThumbsView");
    var CThumbnail_DocViewEventHandler = require('./ThumbnailDocViewEventHandler');
    FXREADER.CThumbNailPlugin = function (pReaderApp) {
        var _pReaderApp = pReaderApp,
              _pThumbsView = null,
              _Language = _pReaderApp.GetLanguage(),
              _self = this;

        //下面实现 INavigationChildPanel接口;
        this.GetPanelID = function () {
            return "fxThumbView";
        };
        this.GetTabBtnID = function () {
            return "thumbtab";
        };
        this.GetTabNorImgUrl = function () {
            return "./images/thumbnail_tab_nor.png";
        };
        this.GetTabHotImgUrl = function () {
            return "./images/thumbnail_tab_nor.png";
        };
        this.GetTitle = function () {
            return _Language.ThumbNail.Title;
        };
        this.OnSize = function (nPanelWidth, nPanelHeight) {
            $("#" + _self.GetPanelID()).css({ width: nPanelWidth, height: nPanelHeight });
            if (_pThumbsView)
                _pThumbsView.OnSize(nPanelWidth, nPanelHeight);
        }
        //end INavigationChildPanel接口;




        //获取Plugin名称;
        this.GetPluginName = function () {
            return "ThumbNail Plugin";
        }
        //插件被注册的时候调用;
        this.PIOnRegister = function () {
        }
        //模块初始化;
        this.PIInit = function () {
            _pThumbsView = new CPDF_PageThumbsView(_pReaderApp.GetMainView().GetDocView().GetPDFDoc(), _self.GetPanelID(),_pReaderApp);
            _pThumbsView.Init();
            _self.BindEvents();
            var pThumbnailDocViewEventHandler = new CThumbnail_DocViewEventHandler(_self);
            _pReaderApp.RegisterDocViewEventHandler(pThumbnailDocViewEventHandler);
            _pThumbsView.SetThumbFocus(_pReaderApp.GetMainView().GetDocView().GetCurPageIndex());
            _pReaderApp.StepProgress();
        }
        //模块卸载;
        this.PIUnload = function () {
        }

        this.GetReaderApp = function () {
            return _pReaderApp;
        }

        this.BindEvents = function () {
            $('.thumbimage').live('mousedown', function (event) {
                if (event.button == 0 || event.button == 1) {
                    try {
                        var nPageIndex = parseInt(event.target.getAttribute("page-index"));
                        _pReaderApp.GetMainView().GetDocView().GotoPage(nPageIndex);
                        _pThumbsView.SetSelectedPage(nPageIndex);
						if (FXREADER.Environment.mobile || FXREADER.Environment.iOS) {
							  var wapNavigationPanelPlugin = _pReaderApp.GetPluginByName(FXREADER.WapNavigationPanelPluginName);
							if(wapNavigationPanelPlugin != null)
							{
								wapNavigationPanelPlugin.Hide();
							}
						}
                    }
                    catch (err) {
                        throw err;
                        return false;
                    }
                }

            });
        }

        this.OnPageIndexUpdated = function (iPageIndex) {
            _pThumbsView.SetThumbFocus(iPageIndex);
        }

    }

    exports.Reader_CreatePlugin = function (pReaderApp) {
        var pThumbnailPlugin = new FXREADER.CThumbNailPlugin(pReaderApp);
        return pThumbnailPlugin;
    }
});